package jmine.tec.persist;

import bancosys.tec.exception.LocalizedMessageHolder;
import bancosys.tec.exception.MessageCreator;
import bancosys.tec.exception.MessageCreatorHelper;

/**
 * @author lundberg
 */
public enum PersistMessages implements MessageCreator {

    DATA_ALREADY_IN_AUTHORIZATION(2, "persist.dataAlreadyInAuthorization"),

    STALE_STATE_IN_AUTHORIZATION(2, "persist.staleStateInAuthorization"),

    REQUIRED_FIELD(1, "persist.validationError.requiredField"),

    ONE_OF_FIELDS_REQUIRED(2, "persist.validationError.oneOfTheFielsRequired"),

    FIELD_VALUE_GREATER_THAN_ZERO(1, "persist.validationError.valueGreaterThanZero"),

    FIELD_VALUE_EQUAL_GREATER_THAN_ZERO(1, "persist.validationError.valueGreaterEqualsZero"),

    UNIQUE_ENTITY(3, "persist.validationError.uniqueValidationMessage"),

    TERM_NOT_FOUND(0, "persist.termNotFound"),

    ERROR_AUTH_STALE_STATE(2, "persist.staleStateInAuthorization"),

    ENTITY_NOT_FOUND(2, "persist.beanNotFoundWithEntityId"),

    DAO_NOT_FOUND(1, "persist.daoNotFound"),

    SYSTEM_ID_PROPERTY_NOT_FOUND(1, "persist.systemIdPropertyNotFound"),

    HOT_COLD_FILTER_NOT_FOUND(0, "persist.hotColdFilterNotFound"),

    COULD_NOT_GET_ENUM_INVOCATION_EXCEPTION(0, "persist.couldNotGetEnum.invocationException"),

    VALIDATION_ERROR_VALUE_LESS_THAN_ZERO(1, "persist.validationError.valueLessThanZero"),

    UNABLE_TO_GET_VALIDATOR_FOR_NULL_TARGET(0, "persist.unableToGetValidatorForNullTarget"),

    VALIDATION_ERROR_INVALID_DATE_UPDATE(0, "persist.validationError.invalidDateUpdate"),

    VALIDATION_ERROR_INVALID_DATE(0, "persist.validationError.invalidDate"),

    VALIDATION_ERROR_ONE_OF_THE_FIELS_REQUIRED(2, "persist.validationError.oneOfTheFielsRequired"),

    INVALID_BEAN_IMPLEMENTATION(1, "persist.invalidBeanImplementation"),

    ERROR_EXECUTING_UPDATE(0, "persist.errorExecutingUpdate"),

    AUTHORIZATION_ERROR(2, "persist.authorizationError"),

    VALIDATION_ERROR_VALUE_GREATER_EQUALS_ZERO(1, "persist.validationError.valueGreaterEqualsZero"),

    ERROR_DURING_FLUSH_UNABLE_TO_COMMIT(0, "persist.errorDuringFlush.unableToCommit"),

    BEAN_NOT_FOUND_WITH_ID(1, "persist.beanNotFoundWithId"),

    UNABLE_TO_INSTANTIATE_PERSISTER(1, "persist.unableToInstantiatePersister"),

    VALIDATION_ERROR_TERM_START_AFTER_END(2, "persist.validationError.termStartAfterEnd"),

    DATA_NOT_IN_AUTHORIZATION(2, "persist.dataNotInAuthorization"),

    ERROR_CONVERTING_TO_UPPER_CASE(1, "persist.errorConvertingToUpperCase"),

    VALIDATION_ERROR_TERM_END_DATE_MISSING(0, "persist.validationError.termEndDateMissing"),

    VALIDATION_ERROR_VALUE_GREATER_THAN_ZERO(1, "persist.validationError.valueGreaterThanZero"),

    HIBERNATE_CONFIGURATION_ERROR(1, "persist.hibernateConfigurationError"),

    VALIDATION_ERROR_DATE_BEFORE_LAST_RECORDED(0, "persist.validationError.dateBeforeLastRecorded"),

    ERROR_UPDATING_VALUE(0, "persist.errorUpdatingValue"),

    VALIDATION_ERROR_ONLY_ONE_TERM(0, "persist.validationError.onlyOneTerm"),

    VALIDATION_ERROR_CANT_REMOVE_NULL(0, "persist.validationError.cantRemoveNull"),

    VALIDATION_ERROR_ONLY_LAST_TERM_CAN_BE_UPDATED(0, "persist.validationError.onlyLastTermCanBeUpdated"),

    VALIDATION_ERROR_UNIQUE_VALIDATION_MESSAGE(3, "persist.validationError.uniqueValidationMessage"),

    VALIDATION_ERROR_AT_LEAST_ONE_TERM(0, "persist.validationError.atLeastOneTerm"),

    ERROR_CLEANING_FIELD_HISTORY(2, "persist.errorCleaningFieldHistory"),

    VALIDATION_ERROR_REQUIRED_FIELD(1, "persist.validationError.requiredField"),

    VALIDATION_ERROR_CANT_REMOVE_DUE_TO_DEPENDENCIES(2, "persist.validationError.cantRemoveDueToDependencies"),

    SAME_USER_AUTHORIZATION(2, "persist.sameUserAuthorization"),

    SESSION_FACTORY_NOT_FOUND(0, "persist.sessionFactoryNotFound"),

    TOO_MANY_BEANS_FOUND(1, "persist.tooManyBeansFound"),

    BEAN_NOT_AUTHORIZED(1, "persist.beanNotAuthorized"),

    VALIDATION_ERROR(2, "persist.validationError"),

    VALIDATION_ERROR_TERM_START_DATE_MISSING(0, "persist.validationError.termStartDateMissing"),

    ID_NOT_SERIALIZABLE(1, "persist.idNotSerializable"),

    NOT_MAPPED(1, "persist.notMapped"),

    UNABLE_TO_INSTANTIATE_VALIDATOR(1, "persist.unableToInstantiateValidator"),

    SINGLETON_APPLICATION_CONTEXT_ALREADY_INITIALIZED(2, "persist.singletonApplicationContextAlreadyInitialized"),

    VALIDATION_ERROR_OBJECT_MUST_HAVE_ONE_TERM_ONLY(0, "persist.validationError.objectMustHaveOneTermOnly"),

    SETTER_METHOD_NOT_FOUND(1, "persist.setterMethodNotFound"),

    VALIDATION_ERROR_BEAN_NOT_FOUND_ON_HOT_PARTITION(0, "persist.validationError.beanNotFoundOnHotPartition"),

    VALIDATION_ERROR_TERM_START_MUST_MATCH_PRIOR_TERM(1, "persist.validationError.termStartMustMatchPriorTerm"),

    NO_TRANSACTION_FOR_CONCURRENT_THREAD_UNABLE_TO_COMMIT(0, "persist.noTransactionForConcurrentThread.unableToCommit"),

    BEAN_NOT_FOUND(1, "persist.beanNotFound"),

    AUTHORIZATION_DENIED(3, "persist.authorizationDenied"),

    VALIDATION_ERROR_HIBERNATE_VALIDATION(1, "persist.validationError.hibernateValidation"),

    ERROR_REJECTING_AUTHORIZATION(2, "persist.errorRejectingAuthorization"),

    TRAVERSE_UNKNOWN(0, "persist.traverse.unknown"),

    TEST_ERROR(0, "persist.test.error"),

    NATURALKEY_INVALID(2, "persist.naturalkey.invalid"),

    ERROR_READING_UNIQUE_VALUE(0, "persist.errorReadingUniqueValue"),

    NOT_AUTHORIZABLE_OBJECT_CASCADED_FROM_AUTHORIZABLE(2, "persist.notAuthorizableObjectCascadedFromAuthorizable"),

    UNABLE_TO_INSTANTIATE_DAO(1, "persist.unableToInstantiateDAO"),

    VALIDATION_ERROR_SIZE_LARGER_THAN_ALLOWED(2, "persist.validationError.sizeLargerThanAllowed"),

    SYSTEM_ENTITY_NOT_FOUND(2, "persist.systemEntityNotFound"),

    GENERIC_PERSISTENCE_ERROR(0, "persist.genericPersistenceError"),

    COULD_NOT_GET_ENUM_NO_SUCH_METHOD(0, "persist.couldNotGetEnum.noSuchMethod"),

    COULD_NOT_GET_ENUM_ILLEGAL_ACCESS(0, "persist.couldNotGetEnum.illegalAccess"),

    BASIC_DATA_NOT_FOUND(2, "persist.basicDataNotFound"),

    GETTER_METHOD_NOT_FOUND(1, "persist.getterMethodNotFound"),

    ID_NOT_FOUND(1, "persist.idNotFound"),

    UNABLE_TO_INITIALIZE_TRANSACTION(0, "persist.unableToInitializeTransaction"),

    VALIDATION_ERROR_ONLY_ONE_REMOVAL_AT_ATIME(0, "persist.validationError.onlyOneRemovalAtATime"),

    UNEXPECTED_ERROR(1, "persist.unexpected.error"),

    NULL_ENUM_CLASS(0, "persist.nullEnumClass"),

    ERROR_REMOVING_BEAN(1, "persist.errorRemovingBean"),

    NATURAL_KEY_NOT_DEFINED(1, "persist.naturalKeyNotDefined"),

    VALIDATION_ERROR_NO_TERM_UPDATE_WHILE_INSERTING(0, "persist.validationError.noTermUpdateWhileInserting"),

    VALIDATION_ERROR_LAST_TERM_START_BEFORE_PRIOR_TERM_START(2, "persist.validationError.lastTermStartBeforePriorTermStart"),

    VALIDATION_ERROR_DATE_UPDATE_NOT_ALLOWED(0, "persist.validationError.dateUpdateNotAllowed"),

    BEAN_NOT_ON_STANDARD_PACKAGE(1, "persist.beanNotOnStandardPackage"),

    COULD_NOT_GET_ENUM_NOT_FOUND(2, "persist.couldNotGetEnum.notFound"),

    ERROR_SETTING_UNIQUE_VALUE(0, "persist.errorSettingUniqueValue"),

    VALIDATION_ERROR_VALUE_LESS_EQUALS_ZERO(1, "persist.validationError.valueLessEqualsZero"),

    VALIDATION_ERROR_ONLY_LAST_TERM_CAN_BE_REMOVED(0, "persist.validationError.onlyLastTermCanBeRemoved"),

    UNABLE_TO_INSTANTIATE_BEAN(1, "persist.unableToInstantiateBean"),

    ERROR_EXECUTING_QUERY(0, "persist.errorExecutingQuery"),

    BEAN_NOT_FOUND_WITH_ENTITY_ID(2, "persist.beanNotFoundWithEntityId"),

    ERROR_LOADING_ORIGINAL_DATA(2, "persist.errorLoadingOriginalData"),

    VALIDATION_ERROR_ONLY_LAST_TERM_CAN_BE_INSERTED(0, "persist.validationError.onlyLastTermCanBeInserted"),

    VALIDATION_ERROR_CANT_INSERT_NULL(0, "persist.validationError.cantInsertNull"),

    UNSUPORTED_COLLECTION_TYPE(1, "persist.unsuportedCollectionType"),

    ERROR_SAVING_AUDIT_LOG(0, "persist.errorSavingAuditLog"),

    NOT_ANNOTATION_CONFIGURATION(0, "persist.notAnnotationConfiguration"),

    UNABLE_TO_VALIDATE(1, "persist.unableToValidate"),

    VALIDATION_ERROR_HIBERNATE_VALIDATION_2(2, "persist.validationError.hibernateValidation2"),

    VALIDATION_ERROR_DATA_ALREADY_ON_DATABASE(0, "persist.validationError.dataAlreadyOnDatabase"),

    VALIDATION_ERROR_DECIMAL_DIGITS_LARGER_THAN_ALLOWED(2, "persist.validationError.decimalDigitsLargerThanAllowed"),

    VALIDATION_ERROR_NO_TERM_UPDATE_WHILE_REMOVING(0, "persist.validationError.noTermUpdateWhileRemoving"),

    ERROR_SAVING_BEAN(1, "persist.errorSavingBean"),

    DATA_ALREADY_AUTHORIZED(2, "persist.dataAlreadyAuthorized"),

    AUTHORIZATION_NOT_PERMITTED(2, "persist.authorizationNotPermitted"),

    REJECTION_NOT_PERMITTED(2, "persist.rejectionNotPermitted"),

    VALIDATION_ERROR_CANT_UPDATE_NULL(0, "persist.validationError.cantUpdateNull"),

    MORE_THAN_ONE_REGISTER_WAITING_AUTHORIZATION(2, "persist.moreThanOneRegisterWaitingAuthorization"),

    UNABLE_TO_GET_ID(1, "persist.unableToGetId"),

    BEAN_NOT_FOUND_BY_NATURAL_KEY(2, "persist.bean.not.found.by.natural.key"),

    ERROR_READING_COLUMN(1, "persist.error.reading.collumn"),

    INTEGER_PART_LARGER_THAN_ALLOWED_FOR_ENTITY(5, "persist.validationError.integerPartLargerThanAllowedForEntity"),

    DECIMAL_DIGITS_LARGER_THAN_ALLOWED_FOR_ENTITY(5, "persist.validationError.decimalDigitsLargerThanAllowedForEntity"),

    NATURAL_KEY_HANDLER_NOT_FOUND(1, "persist.naturalkey.handlerNotFound"),

    ALTERNATE_KEY_NAME_NOT_DEFINED(3, "persist.alternatekey.nameNotDefined"),

    ALTERNATE_KEY_NONSTANDART_NAME(3, "persist.alternatekey.nonstandardName"),

    ALTERNATE_KEY_COLUMN_NOT_FOUND(3, "persist.alternatekey.columnNotFound"),

    ALTERNATE_KEY_NULLABLE_COLUMN(3, "persist.alternatekey.nullableColumn");

    public static final String DEFAULT_BUNDLE = "jmine-tec-persist-messages";

    private final MessageCreator delegate;

    /**
     * Construtor
     * 
     * @param nargs nargs
     * @param key key
     */
    private PersistMessages(int nargs, String key) {
        this(DEFAULT_BUNDLE, key, nargs);
    }

    /**
     * Construtor
     * 
     * @param bundle bundle
     * @param key key
     * @param nargs nargs
     */
    private PersistMessages(String bundle, String key, int nargs) {
        this.delegate = MessageCreatorHelper.creator(bundle, key, nargs);
    }

    /**
     * {@inheritDoc}
     */
    public LocalizedMessageHolder create(Object... arguments) {
        return this.delegate.create(arguments);
    }

    /**
     * {@inheritDoc}
     */
    public int getExpectedArguments() {
        return this.delegate.getExpectedArguments();
    }
}
